package server;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

public class TopicBasedListener implements MessageListener {
	
	private TopicBasedServer server;
	
	
	public TopicBasedListener(TopicBasedServer server){
		this.server = server;
	}

	public void onMessage(Message message) {
		
		try {
			
			TextMessage msg = (TextMessage) message;
			int lastLoadReceived = Integer.valueOf(msg.getText());
			
			//System.out.println("new load received: " + lastLoadReceived);	
			
			server.setLastLoadReceived(lastLoadReceived);						

		    server.interruptTBController();
			
			server.verify();
			
		} catch (JMSException e) {
			e.printStackTrace();
		} 		

	}

}
